package org.lex.collection.tree;

import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

public class SwingTreeModel implements TreeModel {
	private ITreeNode root = null;

	public SwingTreeModel(ITreeNode root) {
		this.root = root;
	}

	@Override
	public Object getChild(Object parent, int index) {
		return ((ITreeNode) parent).getChild(index);
	}

	@Override
	public int getChildCount(Object parent) {
		return ((ITreeNode) parent).getChildCount();
	}

	@Override
	public int getIndexOfChild(Object parent, Object child) {
		ITreeNode pn = ((ITreeNode) parent);
		for (int i = 0, n = pn.getChildCount(); i < n; i++) {
			if (child == pn.getChild(i)) {
				return i;
			}
		}
		return -1;
	}

	@Override
	public Object getRoot() {
		return root;
	}

	@Override
	public boolean isLeaf(Object node) {
		return false == ((ITreeNode) node).hasChildren();
	}

	@Override
	public void valueForPathChanged(TreePath path, Object newValue) {
		// TODO Auto-generated method stub

	}

	@Override
	public void addTreeModelListener(TreeModelListener l) {
		// TODO Auto-generated method stub

	}

	@Override
	public void removeTreeModelListener(TreeModelListener l) {
		// TODO Auto-generated method stub

	}
}
